{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "###########调包\n",
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from datetime import *\n",
    "import time\n",
    "import pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "############数据文件文件路径\n",
    "train_dir = '../../contest/train/'\n",
    "B_dir = '../../contest/B榜/'\n",
    "train_pickle_dir = './pickle/train/'\n",
    "B_pickle_dir = './pickle/B/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_kurt(series_x):\n",
    "    kurt = series_x.kurt()\n",
    "    return kurt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def 加工法人代表资产():\n",
    "    res = []\n",
    "    for data_dir,pickle_dir in [(train_dir,train_pickle_dir),(B_dir,B_pickle_dir)]:\n",
    "        if data_dir==train_dir:\n",
    "            法人代表AUM_T0 = pd.read_csv(os.path.join(data_dir,'XW_RPSTV_HOLD_PD.csv'))  \n",
    "        else:\n",
    "            法人代表AUM_T0 = pd.read_csv(os.path.join(data_dir,'XW_RPSTV_HOLD_PD_B.csv'))\n",
    "\t\t\t\n",
    "        法人代表AUM_T0.columns = ['数据日期','法定代表人客户ID','存款余额','活期存款余额','贷款余额','理财余额','基金余额','国债余额','保险余额','金融资产余额','AUM余额']\n",
    "\n",
    "        法人代表AUM_T0.sort_values(['法定代表人客户ID','数据日期'],inplace=True,ascending=True)\n",
    "\n",
    "        for a in list(法人代表AUM_T0.filter(regex='余额')):\n",
    "           法人代表AUM_T0[a] = pow((法人代表AUM_T0[a])/3.12,3).round(2)\n",
    "\n",
    "        法人代表AUM_T0['数据日期'] = 法人代表AUM_T0['数据日期'].astype('str')\n",
    "        法人代表AUM_T0['数据日期'] = 法人代表AUM_T0['数据日期'].astype('datetime64[ns]')\n",
    "        法人代表AUM_T0['数据日期']=pd.to_datetime(法人代表AUM_T0['数据日期'])+pd.DateOffset(days=11886)\n",
    "        \n",
    "        法人代表AUM_T0.drop_duplicates(inplace=True)\n",
    "\t\t\n",
    "        法人代表AUM_T0['资产汇总']=法人代表AUM_T0['存款余额']+法人代表AUM_T0['理财余额']+\\\n",
    "        法人代表AUM_T0['基金余额']+法人代表AUM_T0['国债余额']+法人代表AUM_T0['保险余额']\n",
    "\t\t\n",
    "        法人代表AUM_T0['资金潜力']=法人代表AUM_T0['资产汇总']-法人代表AUM_T0['AUM余额']\n",
    "        法人代表AUM_T0['定期资产']=法人代表AUM_T0['资产汇总']-法人代表AUM_T0['活期存款余额']\n",
    "\t\t\n",
    "        #法人代表AUM_T0.drop(['存款余额','理财余额','基金余额','国债余额','保险余额','金融资产余额','资产汇总'],axis=1,inplace=True)\n",
    "\n",
    "        法人代表AUM_T0['环比活期差']=法人代表AUM_T0.groupby(['法定代表人客户ID'])['活期存款余额'].diff(1)\n",
    "        法人代表AUM_T0['定期资产差']=法人代表AUM_T0.groupby(['法定代表人客户ID'])['定期资产'].diff(1)\n",
    "        法人代表AUM_T0['环比AUM差']=法人代表AUM_T0.groupby(['法定代表人客户ID'])['AUM余额'].diff(1)\n",
    "        法人代表AUM_T0['环比贷款差']=法人代表AUM_T0.groupby(['法定代表人客户ID'])['贷款余额'].diff(1)\n",
    "\t\t\n",
    "        法人代表AUM_T0['环比活期'] =np.where((法人代表AUM_T0.groupby(['法定代表人客户ID'])['活期存款余额'].shift(1)<50000),np.nan,(法人代表AUM_T0['环比活期差']*100/\\\n",
    "\t\t(法人代表AUM_T0.groupby(['法定代表人客户ID'])['活期存款余额'].shift(1))).round(2))\n",
    "\t\t\n",
    "        法人代表AUM_T0['环比AUM'] =np.where((法人代表AUM_T0.groupby(['法定代表人客户ID'])['AUM余额'].shift(1)<50000),np.nan,(法人代表AUM_T0['环比AUM差']*100/\\\n",
    "\t\t(法人代表AUM_T0.groupby(['法定代表人客户ID'])['AUM余额'].shift(1))).round(2))\n",
    "\t\t\n",
    "        法人代表AUM_T1=法人代表AUM_T0.groupby(['法定代表人客户ID']).agg({'活期存款余额':['last','mean','std'],\\\n",
    "\t\t'定期资产':['last'],'定期资产差':['sum'],'环比贷款差':['sum']\\\n",
    "\t\t,'AUM余额':['last','mean','std','max'],'资金潜力':['sum','max']\\\n",
    "\t\t,'环比活期':['last','mean','min'],'环比活期差':['last','sum','skew',get_kurt,'std']\\\n",
    "\t\t,'环比AUM差':['last','sum','skew',get_kurt,'std'],'环比AUM':['last','mean','min'],'数据日期':['count']})\n",
    "        result=[]\n",
    "        for col in 法人代表AUM_T1.columns.values:\n",
    "            tmp= col[0]+'_'+col[1]\n",
    "            result.append(tmp)\n",
    "        法人代表AUM_T1.columns = result\n",
    "        法人代表AUM_T1.reset_index(inplace=True)\n",
    "\n",
    "        法人代表AUM_T1['个人活期_标准偏差'] = (100*法人代表AUM_T1['活期存款余额_std']/法人代表AUM_T1['活期存款余额_mean']).round(2)\n",
    "        法人代表AUM_T1['个人AUM_标准偏差'] = (100*法人代表AUM_T1['AUM余额_std']/法人代表AUM_T1['AUM余额_mean']).round(2)\n",
    "\t\t\n",
    "        if data_dir==train_dir:\n",
    "            目标客户列表 = pd.read_csv(os.path.join(data_dir,'XW_TARGET.csv'))\n",
    "            目标客户列表.columns = ['借款合同编号','客户ID','纳税人识别号','法定代表人客户ID','违约标记']\n",
    "            目标客户列表.drop(['违约标记'],axis=1,inplace=True)\n",
    "        else:\n",
    "            目标客户列表 = pd.read_csv(os.path.join(data_dir,'XW_TARGET_B.csv'))\n",
    "            目标客户列表.columns = ['借款合同编号','客户ID','纳税人识别号','法定代表人客户ID']\n",
    "\n",
    "        法人代表AUM特征=目标客户列表.merge(法人代表AUM_T1,on=['法定代表人客户ID'],how='left')\n",
    "        法人代表AUM特征.drop(['借款合同编号','纳税人识别号','法定代表人客户ID'],axis=1,inplace=True)\n",
    "\n",
    "        pickle.dump(法人代表AUM特征, open(pickle_dir+'法人代表AUM特征.p', 'wb'))\n",
    "        res.append(法人代表AUM特征)\n",
    "    return res[0],res[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "法人代表资产_训练集,法人代表资产_测试集=加工法人代表资产()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(50000, 32)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "法人代表资产_训练集.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5939, 32)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "法人代表资产_测试集.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def 加工法定代表人金融资产特征补充():\n",
    "    res = [] \n",
    "    for data_dir,pickle_dir in [(train_dir,train_pickle_dir),(B_dir,B_pickle_dir)]:\n",
    "        if data_dir==train_dir:\n",
    "            AUM_T0 = pd.read_csv(os.path.join(data_dir,'XW_RPSTV_HOLD_PD.csv'))    \n",
    "        else:\n",
    "            AUM_T0 = pd.read_csv(os.path.join(data_dir,'XW_RPSTV_HOLD_PD_B.csv'))\n",
    "                \n",
    "        AUM_T0.columns = ['数据日期','法定代表人客户ID','存款余额','活期存款余额','贷款余额','理财余额','基金余额','国债余额','保险余额','金融资产余额','AUM余额']\n",
    "        \n",
    "        AUM_T0.sort_values(['法定代表人客户ID','数据日期'],inplace=True,ascending=True)\n",
    "        \n",
    "        AUM_T0.drop_duplicates(subset=None,keep='first',inplace=True)\n",
    "        \n",
    "        for a in list(AUM_T0.filter(regex='余额')):\n",
    "           AUM_T0[a] = pow((AUM_T0[a])/3.12,3).round(2)\n",
    "        \n",
    "        #近12个月数据金额暴力特征\n",
    "        AUM_T1=AUM_T0.groupby(['法定代表人客户ID']).agg({'存款余额':['mean','max','min','std','last'],'活期存款余额':['mean','max','min','std','last'],'贷款余额':['mean','max','min','std','last']\\\n",
    "                                                 ,'金融资产余额':['mean','max','min','std','last'],'AUM余额':['mean','max','min','std','last']})\n",
    "        AUM_T1.reset_index(inplace=True)\n",
    "        AUM_T1.columns = ['法定代表人客户ID','存款余额平均','存款余额最大','存款余额最小','存款余额标准','存款余额最新','活期存款余额平均','活期存款余额最大','活期存款余额最小','活期存款余额标准','活期存款余额最新'\\\n",
    "                         ,'贷款余额平均','贷款余额最大','贷款余额最小','贷款余额标准','贷款余额最新','金融资产余额平均','金融资产余额最大','金融资产余额最小','贷金融资产余额标准','金融资产余额最新'\\\n",
    "                         ,'AUM余额平均','AUM余额最大','AUM余额最小','AUM余额标准','AUM余额最新']\n",
    "        \n",
    "        AUM_T1['最新存款差值']=AUM_T1['存款余额最新']-AUM_T1['贷款余额最新']\n",
    "        AUM_T1['平均存款差值']=AUM_T1['存款余额平均']-AUM_T1['贷款余额平均']\n",
    "       \n",
    "#         \n",
    "        #近6个月数据金额暴力特征\n",
    "        AUM_T2=AUM_T0[AUM_T0['数据日期']==19880316]\n",
    "        AUM_T2=AUM_T2.groupby(['法定代表人客户ID']).agg({'存款余额':['mean','max','min','std'],'活期存款余额':['mean','max','min','std'],'贷款余额':['mean','max','min','std']\\\n",
    "                                                 ,'金融资产余额':['mean','max','min','std'],'AUM余额':['mean','max','min','std']})\n",
    "        AUM_T2.reset_index(inplace=True)\n",
    "        AUM_T2.columns = ['法定代表人客户ID','近6个月存款余额平均','近6个月存款余额最大','近6个月存款余额最小','近6个月存款余额标准','近6个月活期存款余额平均','近6个月活期存款余额最大','近6个月活期存款余额最小','近6个月活期存款余额标准'\\\n",
    "                         ,'近6个月贷款余额平均','近6个月贷款余额最大','近6个月贷款余额最小','近6个月贷款余额标准','近6个月金融资产余额平均','近6个月金融资产余额最大','近6个月金融资产余额最小','近6个月贷金融资产余额标准'\\\n",
    "                         ,'近6个月AUM余额平均','近6个月AUM余额最大','近6个月AUM余额最小','近6个月AUM余额标准']\n",
    "        \n",
    "        AUM_T2['近6个月差值']=AUM_T2['近6个月存款余额平均']-AUM_T2['近6个月贷款余额平均']\n",
    "        \n",
    "      \n",
    "        #近3个月数据金额暴力特征\n",
    "        AUM_T3=AUM_T0[AUM_T0['数据日期']==19880616]\n",
    "        AUM_T3=AUM_T3.groupby(['法定代表人客户ID']).agg({'存款余额':['mean','max','min','std'],'活期存款余额':['mean','max','min','std'],'贷款余额':['mean','max','min','std']\\\n",
    "                                                 ,'金融资产余额':['mean','max','min','std'],'AUM余额':['mean','max','min','std']})\n",
    "        AUM_T3.reset_index(inplace=True)\n",
    "        AUM_T3.columns = ['法定代表人客户ID','近3个月存款余额平均','近3个月存款余额最大','近3个月存款余额最小','近3个月存款余额标准','近3个月活期存款余额平均','近3个月活期存款余额最大','近3个月活期存款余额最小','近3个月活期存款余额标准'\\\n",
    "                         ,'近3个月贷款余额平均','近3个月贷款余额最大','近3个月贷款余额最小','近3个月贷款余额标准','近3个月金融资产余额平均','近3个月金融资产余额最大','近3个月金融资产余额最小','近3个月贷金融资产余额标准'\\\n",
    "                         ,'近3个月AUM余额平均','近3个月AUM余额最大','近3个月AUM余额最小','近3个月AUM余额标准']\n",
    "        \n",
    "        AUM_T3['近3个月差值']=AUM_T3['近3个月存款余额平均']-AUM_T3['近3个月贷款余额平均']\n",
    "\n",
    "        \n",
    "        #同比\n",
    "        AUM_T4=AUM_T0[AUM_T0['数据日期']==19880616 ]\n",
    "        AUM_T4=AUM_T4.groupby(['法定代表人客户ID']).agg({'存款余额':['mean'],'活期存款余额':['mean'],'贷款余额':['mean']\\\n",
    "                                                 ,'金融资产余额':['mean'],'AUM余额':['mean']})\n",
    "        AUM_T4.reset_index(inplace=True)\n",
    "        AUM_T4.columns = ['法定代表人客户ID','近三个月存款余额','近三个月活期存款余额','近三个月贷款余额','近三个月金融资产余额','近三个月AUM余额']\n",
    "        \n",
    "        AUM_T5=AUM_T0[AUM_T0['数据日期']==19880316]\n",
    "        AUM_T5=AUM_T5.groupby(['法定代表人客户ID']).agg({'存款余额':['mean'],'活期存款余额':['mean'],'贷款余额':['mean']\\\n",
    "                                                 ,'金融资产余额':['mean'],'AUM余额':['mean']})\n",
    "        AUM_T5.reset_index(inplace=True)\n",
    "        AUM_T5.columns = ['法定代表人客户ID','近六个月存款余额','近六个月活期存款余额','近六个月贷款余额','近六个月金融资产余额','近六个月AUM余额']\n",
    "        AUM_T5['存款余额差']=AUM_T4['近三个月存款余额']-AUM_T5['近六个月存款余额']\n",
    "        AUM_T5['活期存款余额差']=AUM_T4['近三个月活期存款余额']-AUM_T5['近六个月活期存款余额']\n",
    "        AUM_T5['贷款余额差']=AUM_T4['近三个月贷款余额']-AUM_T5['近六个月贷款余额']\n",
    "        AUM_T5['金融资产余额差']=AUM_T4['近三个月金融资产余额']-AUM_T5['近六个月金融资产余额']\n",
    "        AUM_T5['AUM余额差']=AUM_T4['近三个月AUM余额']-AUM_T5['近六个月AUM余额']\n",
    "        \n",
    "        #贷款预测\n",
    "        贷款余额最新期=AUM_T0[AUM_T0['数据日期']==19880914]\n",
    "        贷款余额最新期=贷款余额最新期.groupby(['法定代表人客户ID']).agg({'存款余额':['mean'],'活期存款余额':['mean'],'贷款余额':['mean']})\n",
    "        贷款余额最新期.reset_index(inplace=True)\n",
    "        贷款余额最新期.columns = ['法定代表人客户ID','存款余额最新期','活期存款余额最新期','贷款余额最新期']\n",
    "        贷款余额第二期=AUM_T0[AUM_T0['数据日期']==19880616]\n",
    "        贷款余额第二期=贷款余额第二期.groupby(['法定代表人客户ID']).agg({'存款余额':['mean'],'活期存款余额':['mean'],'贷款余额':['mean']})\n",
    "        贷款余额第二期.reset_index(inplace=True)\n",
    "        贷款余额第二期.columns = ['法定代表人客户ID','存款余额第二期','活期存款余额第二期','贷款余额第二期']\n",
    "        贷款余额第三期=AUM_T0[AUM_T0['数据日期']==19880316]\n",
    "        贷款余额第三期=贷款余额第三期.groupby(['法定代表人客户ID']).agg({'存款余额':['mean'],'活期存款余额':['mean'],'贷款余额':['mean']})\n",
    "        贷款余额第三期.reset_index(inplace=True)\n",
    "        贷款余额第三期.columns = ['法定代表人客户ID','存款余额第三期','活期存款余额第三期','贷款余额第三期']\n",
    "        贷款余额第四期=AUM_T0[AUM_T0['数据日期']==19871215]\n",
    "        贷款余额第四期=贷款余额第四期.groupby(['法定代表人客户ID']).agg({'存款余额':['mean'],'活期存款余额':['mean'],'贷款余额':['mean']})\n",
    "        贷款余额第四期.reset_index(inplace=True)\n",
    "        贷款余额第四期.columns = ['法定代表人客户ID','存款余额第四期','活期存款余额第四期','贷款余额第四期']\n",
    "        贷款余额第五期=AUM_T0[AUM_T0['数据日期']==19870915]\n",
    "        贷款余额第五期=贷款余额第五期.groupby(['法定代表人客户ID']).agg({'存款余额':['mean'],'活期存款余额':['mean'],'贷款余额':['mean']})\n",
    "        贷款余额第五期.reset_index(inplace=True)\n",
    "        贷款余额第五期.columns = ['法定代表人客户ID','存款余额第五期','活期存款余额第五期','贷款余额第五期']\n",
    "        贷款预测=贷款余额最新期.merge(贷款余额第二期,on=['法定代表人客户ID'],how='left')\n",
    "        贷款预测=贷款预测.merge(贷款余额第三期,on=['法定代表人客户ID'],how='left')\n",
    "        贷款预测=贷款预测.merge(贷款余额第四期,on=['法定代表人客户ID'],how='left')\n",
    "        贷款预测=贷款预测.merge(贷款余额第五期,on=['法定代表人客户ID'],how='left')\n",
    "        \n",
    "        贷款预测['最新差值']=贷款预测['贷款余额最新期']-贷款预测['贷款余额第二期']\n",
    "        贷款预测['第二新差值']=贷款预测['贷款余额第二期']-贷款预测['贷款余额第三期']\n",
    "        贷款预测['第三新差值']=贷款预测['贷款余额第三期']-贷款预测['贷款余额第四期']\n",
    "        贷款预测['第四新差值']=贷款预测['贷款余额第四期']-贷款预测['贷款余额第五期']\n",
    "\n",
    "        \n",
    "  \n",
    "        贷款预测1=贷款预测.groupby(['法定代表人客户ID']).agg({'最新差值':['std']})\n",
    "        贷款预测1.reset_index(inplace=True)\n",
    "        贷款预测1.columns = ['法定代表人客户ID','最新差值比率']\n",
    "        \n",
    "        if data_dir==train_dir:\n",
    "            目标客户列表 = pd.read_csv(os.path.join(data_dir,'XW_TARGET.csv'))\n",
    "            目标客户列表.columns = ['借款合同编号','客户ID','纳税人识别号','法定代表人客户ID','违约标记']\n",
    "            目标客户列表.drop(['违约标记'],axis=1,inplace=True)\n",
    "        else:\n",
    "            目标客户列表 = pd.read_csv(os.path.join(data_dir,'XW_TARGET_B.csv'))\n",
    "            目标客户列表.columns = ['借款合同编号','客户ID','纳税人识别号','法定代表人客户ID']\n",
    "  \n",
    "        法定代表人金融资产特征=目标客户列表.merge(AUM_T1,on=['法定代表人客户ID'],how='left')\n",
    "        法定代表人金融资产特征=法定代表人金融资产特征.merge(AUM_T3,on=['法定代表人客户ID'],how='left')\n",
    "        法定代表人金融资产特征=法定代表人金融资产特征.merge(贷款预测1,on=['法定代表人客户ID'],how='left')\n",
    "\n",
    "        法定代表人金融资产特征.drop(['借款合同编号','纳税人识别号','法定代表人客户ID'],axis=1,inplace=True)\n",
    "\t\t\n",
    "        pickle.dump(法定代表人金融资产特征, open(pickle_dir+'Z法定代表人金融资产特征1.p', 'wb'))\n",
    "        res.append(法定代表人金融资产特征)\n",
    "        \n",
    "    return res[0],res[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def 加工法定代表人金融资产特征补充2():\n",
    "    res = [] \n",
    "    for data_dir,pickle_dir in [(train_dir,train_pickle_dir),(B_dir,B_pickle_dir)]:\n",
    "        if data_dir==train_dir:\n",
    "            AUM_T0 = pd.read_csv(os.path.join(data_dir,'XW_RPSTV_HOLD_PD.csv'))    \n",
    "        else:\n",
    "            AUM_T0 = pd.read_csv(os.path.join(data_dir,'XW_RPSTV_HOLD_PD_B.csv'))\n",
    "                \n",
    "        AUM_T0.columns = ['数据日期','法定代表人客户ID','存款余额','活期存款余额','贷款余额','理财余额','基金余额','国债余额','保险余额','金融资产余额','AUM余额']\n",
    "        AUM_T0.sort_values(['法定代表人客户ID','数据日期'],inplace=True,ascending=True)\n",
    "        AUM_T0.drop_duplicates(subset=None,keep='first',inplace=True)\n",
    "        \n",
    "        AUM_T0['存款余额'] = pow((AUM_T0['存款余额'])/3.12,3)\n",
    "        AUM_T0['活期存款余额'] = pow((AUM_T0['活期存款余额'])/3.12,3)\n",
    "        AUM_T0['贷款余额'] = pow((AUM_T0['贷款余额'])/3.12,3)\n",
    "        AUM_T0['理财余额'] = pow((AUM_T0['理财余额'])/3.12,3)\n",
    "        AUM_T0['基金余额'] = pow((AUM_T0['基金余额'])/3.12,3)\n",
    "        AUM_T0['国债余额'] = pow((AUM_T0['国债余额'])/3.12,3)\n",
    "        AUM_T0['保险余额'] = pow((AUM_T0['保险余额'])/3.12,3)\n",
    "        AUM_T0['金融资产余额'] = pow((AUM_T0['金融资产余额'])/3.12,3)\n",
    "        AUM_T0['AUM余额'] = pow((AUM_T0['AUM余额'])/3.12,3)\n",
    "        \n",
    "        \n",
    "        for a in list(AUM_T0.filter(regex='余额')):\n",
    "                AUM_T0[a] = pow((AUM_T0[a])/0.857,3).round(2)    \n",
    "\n",
    "        AUM_T1=AUM_T0.groupby(['法定代表人客户ID','数据日期']).agg({'存款余额':['sum'],'AUM余额':['sum']})\n",
    "        AUM_T1.reset_index(inplace=True)\n",
    "        AUM_T1.columns = ['法定代表人客户ID','数据日期' ,'存款余额汇总','AUM余额汇总']\n",
    "\n",
    "        AUM_T2=AUM_T1.groupby(['法定代表人客户ID']).agg({'存款余额汇总':['max','min','std','mean'],'AUM余额汇总':['max','min','std','mean']})\n",
    "        AUM_T2.reset_index(inplace=True)\n",
    "        AUM_T2.columns = ['法定代表人客户ID','存款余额汇总_max','存款余额汇总_min','存款余额汇总_std','存款余额汇总_mean',\\\n",
    "                         'AUM余额汇总_max','AUM余额汇总_min','AUM余额汇总_std','AUM余额汇总_mean']\n",
    "        \n",
    "        if data_dir==train_dir:\n",
    "            目标客户列表 = pd.read_csv(os.path.join(data_dir,'XW_TARGET.csv'))\n",
    "            目标客户列表.columns = ['借款合同编号','客户ID','纳税人识别号','法定代表人客户ID','违约标记']\n",
    "            目标客户列表.drop(['违约标记'],axis=1,inplace=True)\n",
    "        else:\n",
    "            目标客户列表 = pd.read_csv(os.path.join(data_dir,'XW_TARGET_B.csv'))\n",
    "            目标客户列表.columns = ['借款合同编号','客户ID','纳税人识别号','法定代表人客户ID']\n",
    "  \n",
    "        法定代表人金融资产特征=目标客户列表.merge(AUM_T2,on=['法定代表人客户ID'],how='left')\n",
    "        法定代表人金融资产特征.fillna(法定代表人金融资产特征.median(),inplace=True)\n",
    "        法定代表人金融资产特征.drop(['借款合同编号','纳税人识别号','法定代表人客户ID'],axis=1,inplace=True)\n",
    "\t\t\n",
    "        pickle.dump(法定代表人金融资产特征, open(pickle_dir+'Z法定代表人金融资产特征2.p', 'wb'))\n",
    "        \n",
    "        res.append(法定代表人金融资产特征)\n",
    "        \n",
    "    return res[0],res[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "法人代表资产补充_训练集,法人代表资产补充_测试集=加工法定代表人金融资产特征补充()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-13-84e75815eb01>:45: FutureWarning: The default value of numeric_only in DataFrame.median is deprecated. In a future version, it will default to False. In addition, specifying 'numeric_only=None' is deprecated. Select only valid columns or specify the value of numeric_only to silence this warning.\n",
      "  法定代表人金融资产特征.fillna(法定代表人金融资产特征.median(),inplace=True)\n",
      "<ipython-input-13-84e75815eb01>:45: FutureWarning: The default value of numeric_only in DataFrame.median is deprecated. In a future version, it will default to False. In addition, specifying 'numeric_only=None' is deprecated. Select only valid columns or specify the value of numeric_only to silence this warning.\n",
      "  法定代表人金融资产特征.fillna(法定代表人金融资产特征.median(),inplace=True)\n"
     ]
    }
   ],
   "source": [
    "法人代表资产补充2_训练集,法人代表资产补充2_测试集=加工法定代表人金融资产特征补充2()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
